/**
 * @param {number[]} nums
 * @return {string[]}
 */
var findRelativeRanks = function(nums) {
  var ranks = new Map()
  for (let i = 0; i < nums.length; i++) {
    ranks.set(nums[i], i)
  }
  ;[...ranks.keys()]
    .sort((a, b) => b - a)
    .forEach((item, index) => {
      switch (index) {
        case 0:
          nums[ranks.get(item)] = "Gold Medal"
          break
        case 1:
          nums[ranks.get(item)] = "Silver Medal"
          break
        case 2:
          nums[ranks.get(item)] = "Bronze Medal"
          break
        default:
          nums[ranks.get(item)] = index + 1 + ""
      }
    })
  return nums
}

console.log(findRelativeRanks([10, 9, 5, 3, 8, 7]))

/*
 * @lc app=leetcode.cn id=506 lang=javascript
 *
 * [506] 相对名次
 */
/**
 * @param {number[]} nums
 * @return {string[]}
 */
var findRelativeRanks2 = function(nums) {
  let res = {
    1: "Gold Medal",
    2: "Silver Medal",
    3: "Bronze Medal"
  }
  let a = []
  nums.forEach(element => {
    a[element] = 1
  })
  let i = nums.length
  for (const key in a) {
    a[key] = i--
  }
  for (let j = 0; j < nums.length; j++) {
    nums[j] = a[nums[j]] + ""
    if (res[nums[j]]) {
      nums[j] = res[nums[j]]
    }
  }
  return nums
}
